// Copyright 2025 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Code generated by sidekick. DO NOT EDIT.
#![allow(rustdoc::redundant_explicit_links)]
#![allow(rustdoc::broken_intra_doc_links)]

/// Implements a client for the Recommender API.
///
/// # Example
/// ```
/// # tokio_test::block_on(async {
/// # use google_cloud_recommender_v1::client::Recommender;
/// let client = Recommender::builder().build().await?;
/// // use `client` to make requests to the Recommender API.
/// # gax::client_builder::Result::<()>::Ok(()) });
/// ```
///
/// # Service Description
///
/// Provides insights and recommendations for cloud customers for various
/// categories like performance optimization, cost savings, reliability, feature
/// discovery, etc. Insights and recommendations are generated automatically
/// based on analysis of user resources, configuration and monitoring metrics.
///
/// # Configuration
///
/// To configure `Recommender` use the `with_*` methods in the type returned
/// by [builder()][Recommender::builder]. The default configuration should
/// work for most applications. Common configuration changes include
///
/// * [with_endpoint()]: by default this client uses the global default endpoint
///   (`https://recommender.googleapis.com`). Applications using regional
///   endpoints or running in restricted networks (e.g. a network configured
//    with [Private Google Access with VPC Service Controls]) may want to
///   override this default.
/// * [with_credentials()]: by default this client uses
///   [Application Default Credentials]. Applications using custom
///   authentication may need to override this default.
///
/// [with_endpoint()]: super::builder::recommender::ClientBuilder::with_endpoint
/// [with_credentials()]: super::builder::recommender::ClientBuilder::credentials
/// [Private Google Access with VPC Service Controls]: https://cloud.google.com/vpc-service-controls/docs/private-connectivity
/// [Application Default Credentials]: https://cloud.google.com/docs/authentication#adc
///
/// # Pooling and Cloning
///
/// `Recommender` holds a connection pool internally, it is advised to
/// create one and the reuse it.  You do not need to wrap `Recommender` in
/// an [Rc](std::rc::Rc) or [Arc](std::sync::Arc) to reuse it, because it
/// already uses an `Arc` internally.
#[derive(Clone, Debug)]
pub struct Recommender {
    inner: std::sync::Arc<dyn super::stub::dynamic::Recommender>,
}

impl Recommender {
    /// Returns a builder for [Recommender].
    ///
    /// ```
    /// # tokio_test::block_on(async {
    /// # use google_cloud_recommender_v1::client::Recommender;
    /// let client = Recommender::builder().build().await?;
    /// # gax::client_builder::Result::<()>::Ok(()) });
    /// ```
    pub fn builder() -> super::builder::recommender::ClientBuilder {
        gax::client_builder::internal::new_builder(super::builder::recommender::client::Factory)
    }

    /// Creates a new client from the provided stub.
    ///
    /// The most common case for calling this function is in tests mocking the
    /// client's behavior.
    pub fn from_stub<T>(stub: T) -> Self
    where
        T: super::stub::Recommender + 'static,
    {
        Self {
            inner: std::sync::Arc::new(stub),
        }
    }

    pub(crate) async fn new(
        config: gaxi::options::ClientConfig,
    ) -> gax::client_builder::Result<Self> {
        let inner = Self::build_inner(config).await?;
        Ok(Self { inner })
    }

    async fn build_inner(
        conf: gaxi::options::ClientConfig,
    ) -> gax::client_builder::Result<std::sync::Arc<dyn super::stub::dynamic::Recommender>> {
        if gaxi::options::tracing_enabled(&conf) {
            return Ok(std::sync::Arc::new(Self::build_with_tracing(conf).await?));
        }
        Ok(std::sync::Arc::new(Self::build_transport(conf).await?))
    }

    async fn build_transport(
        conf: gaxi::options::ClientConfig,
    ) -> gax::client_builder::Result<impl super::stub::Recommender> {
        super::transport::Recommender::new(conf).await
    }

    async fn build_with_tracing(
        conf: gaxi::options::ClientConfig,
    ) -> gax::client_builder::Result<impl super::stub::Recommender> {
        Self::build_transport(conf)
            .await
            .map(super::tracing::Recommender::new)
    }

    /// Lists insights for the specified Cloud Resource. Requires the
    /// recommender.*.list IAM permission for the specified insight type.
    pub fn list_insights(&self) -> super::builder::recommender::ListInsights {
        super::builder::recommender::ListInsights::new(self.inner.clone())
    }

    /// Gets the requested insight. Requires the recommender.*.get IAM permission
    /// for the specified insight type.
    pub fn get_insight(&self) -> super::builder::recommender::GetInsight {
        super::builder::recommender::GetInsight::new(self.inner.clone())
    }

    /// Marks the Insight State as Accepted. Users can use this method to
    /// indicate to the Recommender API that they have applied some action based
    /// on the insight. This stops the insight content from being updated.
    ///
    /// MarkInsightAccepted can be applied to insights in ACTIVE state. Requires
    /// the recommender.*.update IAM permission for the specified insight.
    pub fn mark_insight_accepted(&self) -> super::builder::recommender::MarkInsightAccepted {
        super::builder::recommender::MarkInsightAccepted::new(self.inner.clone())
    }

    /// Lists recommendations for the specified Cloud Resource. Requires the
    /// recommender.*.list IAM permission for the specified recommender.
    pub fn list_recommendations(&self) -> super::builder::recommender::ListRecommendations {
        super::builder::recommender::ListRecommendations::new(self.inner.clone())
    }

    /// Gets the requested recommendation. Requires the recommender.*.get
    /// IAM permission for the specified recommender.
    pub fn get_recommendation(&self) -> super::builder::recommender::GetRecommendation {
        super::builder::recommender::GetRecommendation::new(self.inner.clone())
    }

    /// Mark the Recommendation State as Dismissed. Users can use this method to
    /// indicate to the Recommender API that an ACTIVE recommendation has to
    /// be marked back as DISMISSED.
    ///
    /// MarkRecommendationDismissed can be applied to recommendations in ACTIVE
    /// state.
    ///
    /// Requires the recommender.*.update IAM permission for the specified
    /// recommender.
    pub fn mark_recommendation_dismissed(
        &self,
    ) -> super::builder::recommender::MarkRecommendationDismissed {
        super::builder::recommender::MarkRecommendationDismissed::new(self.inner.clone())
    }

    /// Marks the Recommendation State as Claimed. Users can use this method to
    /// indicate to the Recommender API that they are starting to apply the
    /// recommendation themselves. This stops the recommendation content from being
    /// updated. Associated insights are frozen and placed in the ACCEPTED state.
    ///
    /// MarkRecommendationClaimed can be applied to recommendations in CLAIMED,
    /// SUCCEEDED, FAILED, or ACTIVE state.
    ///
    /// Requires the recommender.*.update IAM permission for the specified
    /// recommender.
    pub fn mark_recommendation_claimed(
        &self,
    ) -> super::builder::recommender::MarkRecommendationClaimed {
        super::builder::recommender::MarkRecommendationClaimed::new(self.inner.clone())
    }

    /// Marks the Recommendation State as Succeeded. Users can use this method to
    /// indicate to the Recommender API that they have applied the recommendation
    /// themselves, and the operation was successful. This stops the recommendation
    /// content from being updated. Associated insights are frozen and placed in
    /// the ACCEPTED state.
    ///
    /// MarkRecommendationSucceeded can be applied to recommendations in ACTIVE,
    /// CLAIMED, SUCCEEDED, or FAILED state.
    ///
    /// Requires the recommender.*.update IAM permission for the specified
    /// recommender.
    pub fn mark_recommendation_succeeded(
        &self,
    ) -> super::builder::recommender::MarkRecommendationSucceeded {
        super::builder::recommender::MarkRecommendationSucceeded::new(self.inner.clone())
    }

    /// Marks the Recommendation State as Failed. Users can use this method to
    /// indicate to the Recommender API that they have applied the recommendation
    /// themselves, and the operation failed. This stops the recommendation content
    /// from being updated. Associated insights are frozen and placed in the
    /// ACCEPTED state.
    ///
    /// MarkRecommendationFailed can be applied to recommendations in ACTIVE,
    /// CLAIMED, SUCCEEDED, or FAILED state.
    ///
    /// Requires the recommender.*.update IAM permission for the specified
    /// recommender.
    pub fn mark_recommendation_failed(
        &self,
    ) -> super::builder::recommender::MarkRecommendationFailed {
        super::builder::recommender::MarkRecommendationFailed::new(self.inner.clone())
    }

    /// Gets the requested Recommender Config. There is only one instance of the
    /// config for each Recommender.
    pub fn get_recommender_config(&self) -> super::builder::recommender::GetRecommenderConfig {
        super::builder::recommender::GetRecommenderConfig::new(self.inner.clone())
    }

    /// Updates a Recommender Config. This will create a new revision of the
    /// config.
    pub fn update_recommender_config(
        &self,
    ) -> super::builder::recommender::UpdateRecommenderConfig {
        super::builder::recommender::UpdateRecommenderConfig::new(self.inner.clone())
    }

    /// Gets the requested InsightTypeConfig. There is only one instance of the
    /// config for each InsightType.
    pub fn get_insight_type_config(&self) -> super::builder::recommender::GetInsightTypeConfig {
        super::builder::recommender::GetInsightTypeConfig::new(self.inner.clone())
    }

    /// Updates an InsightTypeConfig change. This will create a new revision of the
    /// config.
    pub fn update_insight_type_config(
        &self,
    ) -> super::builder::recommender::UpdateInsightTypeConfig {
        super::builder::recommender::UpdateInsightTypeConfig::new(self.inner.clone())
    }
}
